package com.zlq.add.lambda;

import com.zlq.add.entity.User;

import java.util.*;
import java.util.stream.Collectors;

public class TestLambda {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("Brian", "Nate", "Neal", "Raju", "Sara", "Scott");
        //遍历
        list.forEach(name -> System.out.println(name));
        list.forEach(System.out::println);

        //转大写
        list.stream().map(name -> name.toUpperCase(Locale.ROOT)).forEach(System.out::println);
        list.stream().map(String::toUpperCase).forEach(System.out::println);

        //输出有指定包含的字符串
        List<String> s = list.stream().filter(name -> name.startsWith("S")).collect(Collectors.toList());
        System.out.println(s);

        List<User> str = new ArrayList<>();
        str.add(new User("aa",11));
        str.add(new User("cc",16));
        str.add(new User("bb",15));
        //以名字排序
        str.sort(Comparator.comparing(User::getAge));
        str.forEach(System.out::println);

        //排序后反转
        str.sort(Comparator.comparing(User::getAge).thenComparing(User::getName).reversed());
        str.forEach(System.out::println);
    }
}
